###
The HBox widget aligns widgets in a horizontal order.
###

class tree.ui.HBox extends tree.ui.Container
    constructor: () ->
        super
        @connect 'added', @added
        @htmlelem = document.createElement 'table'
        @htmlelem.setAttribute 'class', 'tree-hbox-layout'
    
    added: (evt) =>
        while @htmlelem.hasChildNodes()
            while @htmlelem.childNodes.length >= 1
                @htmlelem.removeChild @htmlelem.firstChild 
        tbody = document.createElement 'tbody'
        tr = document.createElement 'tr'
        tbody.appendChild tr
        @htmlelem.appendChild tbody
        for child in @children
            td = document.createElement 'td'
            tr.appendChild td
            td.appendChild child.show()
        @htmlelem
    
    show: () ->
        super
        tbody = document.createElement 'tbody'
        tr = document.createElement 'tr'
        tbody.appendChild tr
        @htmlelem.appendChild tbody
        for child in @children
            td = document.createElement 'td'
            tr.appendChild td
            td.appendChild child.show()
        @htmlelem
